﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenMinded.IDAL;

namespace OpenMinded.BLL
{
    public class Users
    {
        //从数据访问层工厂类得到一个种类的数据访问层的实例
        //确保这个静态可以在初始化后缓存数据访问层
        private static IUsers dal = OpenMinded.DALFactory.DataAccess.CreateUsers();
        
        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="loginId"></param>
        /// <param name="loginPwd"></param>
        /// <param name="outUser"></param>
        /// <param name="errorNo">错误序号，0：无错误，1：用户不存在，2：密码和用户名不匹配</param>
        /// <returns></returns>
        public bool LoginIn(string loginId,string loginPwd,out OpenMinded.Model.Users outUser,out int errorNo)
        { 
            bool login=false;
            outUser = null;
            errorNo = 0;
            Model.Users user = dal.GetUser(loginId);
            if (user!=null)
            {
                if (user.LoginPwd==Common.GetMD5String(loginPwd))
                {
                    outUser = user;
                    login = true;
                }
                else
                {
                    errorNo = 2;
                }
            }
            else
            {
                errorNo = 1;
            }
            return login;
        }
    }
}
